package com.luyue.zagj.activity.base;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.luyue.zagj.BaseActivity;
import com.luyue.zagj.R;
import com.luyue.zagj.utils.CountDownTimerUtils;
import com.luyue.zagj.utils.ToastUtil;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RegisterActivity extends BaseActivity {

    @Bind(R.id.register_cancel_btn)
    Button registerCancelBtn;
    @Bind(R.id.register_top_rl)
    RelativeLayout registerTopRl;
    @Bind(R.id.register_phone_ed)
    EditText registerPhoneEd;
    @Bind(R.id.register_code_ed)
    EditText registerCodeEd;
    @Bind(R.id.register_get_code_tv)
    TextView registerGetCodeTv;
    @Bind(R.id.register_psw_ed)
    EditText registerPswEd;
    @Bind(R.id.register_btn)
    Button registerBtn;
    @Bind(R.id.register_to_login_tv)
    LinearLayout registerToLoginTv;
    private int i = 60;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.register_cancel_btn, R.id.register_get_code_tv, R.id.register_btn, R.id.register_to_login_tv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.register_cancel_btn:
                onBackPressed();
                break;
            case R.id.register_get_code_tv:
                CountDownTimerUtils mCountDownTimerUtils = new CountDownTimerUtils(registerGetCodeTv, 60000, 1000);
                mCountDownTimerUtils.start();
                break;
            case R.id.register_btn:
                CheckCode();
                break;
            case R.id.register_to_login_tv:
                Intent intent = new Intent(this, LoginActivity.class);
                startActivity(intent);
                finish();
                break;
        }
    }


    private void CheckCode() {
        String phone = registerPhoneEd.getText().toString().trim();
        String code = registerCodeEd.getText().toString().trim();
        String pw = registerPswEd.getText().toString().trim();

        if (!TextUtils.isEmpty(phone)&&!TextUtils.isEmpty(code) && !TextUtils.isEmpty(pw)){
            Intent intent = new Intent(this, RegisterPswProActivity.class);
            startActivity(intent);
            finish();
        }else{
            ToastUtil.getToast("请完善个人信息",this);
        }

    }

}
